//
//  HomeTourCell.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 2017/5/17.
//  Copyright © 2017年 EasyToTesco. All rights reserved.
//

#import "HomeTourCell.h"

#import "SectionView.h"
#import "TourCollectionCell.h"

static NSString * const Tour_Id               = @"Tour_Identifier";

@interface HomeTourCell()<UICollectionViewDelegate,UICollectionViewDataSource>

@property(nonatomic,strong)SectionView      *sectionView;
@property(nonatomic,strong)UICollectionView *tourView;
@property(nonatomic,strong)UICollectionViewFlowLayout *layout;

@end


@implementation HomeTourCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self buildSubViews];
    }
    return self;
}

- (void)buildSubViews
{
    [self.contentView addSubview:self.sectionView];
    [self.contentView addSubview:self.tourView];
    
}


#pragma mark datasource delegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TourCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:Tour_Id forIndexPath:indexPath];
    cell.contentLabel.text = @"爱你";
    cell.contentImg.image = [UIImage imageNamed:@"bg_recommend1"];
    return cell;
}


-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0,15,0,15);
}


#pragma mark lazy
- (SectionView *)sectionView
{
    if (!_sectionView) {
        _sectionView = [[SectionView alloc] initWithFrame:CGRectMake(0,0,WIDTH,40)];
        _sectionView.titleLabel.text = @"周边旅游";
    }
    return _sectionView;
}



- (UICollectionViewFlowLayout *)layout
{
    if (!_layout) {
        _layout = [[UICollectionViewFlowLayout  alloc] init];
        _layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _layout.minimumLineSpacing = 10;
        _layout.minimumInteritemSpacing = 10;
        CGFloat itemW = (WIDTH  -20 -30)/3;
        _layout.itemSize = CGSizeMake(itemW,itemW);
    }
    return _layout;
}

- (UICollectionView *)tourView
{
    if (!_tourView) {
        _tourView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(_sectionView.frame), WIDTH,(WIDTH-50)/3*2+20) collectionViewLayout:self.layout];
        _tourView.delegate = self;
        _tourView.dataSource = self;
        _tourView.backgroundColor = [UIColor whiteColor];
        _tourView.showsHorizontalScrollIndicator = false;
        [_tourView registerClass:[TourCollectionCell class] forCellWithReuseIdentifier:Tour_Id];
    }
    return _tourView;
}





@end
